package jfrederick8;

/**
 * This class creates an item with the ability to house other items.
 * 
 * @author John Frederick
 * @version 1.0 12-14-2011
 */
public class ItemContainer extends Item{
	private Item[] itemList;
	private Item itemTemp;
	private int index;
	private boolean carriable;
	
	//null stats
	/**
	 * 
	 * @param stats the possible stat alterations the ItemContainer could have if held
	 * @param name the name of the container
	 * @param size the number of items which the container can hold
	 * @param classRestriction restricts the holding of the container to certain classes
	 * @param factionRestriction restricts holding to certain factions
	 * @param carriable tells whether someone is able to carry the container
	 */
	public ItemContainer(int[] stats, String name, int size, int classRestriction, int factionRestriction, boolean carriable){
		super(stats, name, "Used to hold " + size + " items", "Container", 7000, 3, (Integer)null, (Integer)null, factionRestriction, classRestriction, (Integer)null, (Integer)null, false, false, (Integer)null);
		this.itemList = new Item[size];
		this.carriable = carriable;
	}//end constructor Container
	
	/**
	 * This method adds an item to the container and returns a check for success
	 * 
	 * @param item an item to add to the container
	 * @return true if item was added, else false
	 */
	public boolean addItem(Item item){
		index = 0;
		while (index<itemList.length){
			if (itemList[index] == null){
				itemList[index] = item;
				return true;
			} else {
				index++;
			}
		}
		return false;
	}//end method addItem
	
	/**
	 * destroys an item in the container
	 * 
	 * @param index the location of the item in the container
	 */
	public void deleteItem(int index){
		itemList[index] = (Item)null;
	}//end method deleteItem
	
	/**
	 * takes an item out of the container
	 * 
	 * @param index the location of the item in the container
	 * @return the item which is being taken
	 */
	public Item takeItem(int index){
		itemTemp = itemList[index];
		itemList[index] = (Item)null;
		return itemTemp;
	}//end method takeItem
	
	/**
	 * gives access to the itemList from the outside
	 * 
	 * @return the list of items in the container
	 */
	public Item[] getContents(){
		return itemList;
	}//end getter getContents
	
	/**
	 * checks for carry-ability of the container
	 * 
	 * @return true or false representing whether the container can be carried.
	 */
	public boolean getCarriable(){
		return carriable;
	}//end getter getCarriable
}//end class Container
